/**
 * 
 */
package org.istt.web;

import org.apache.struts2.ServletActionContext;
import org.istt.domain.User;
import org.istt.service.FileMgrManager;
import org.istt.web.helper.ExtendedPaginatedList;
import org.istt.web.helper.PaginateListFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

/**
 * @author Huy
 * 
 */
public class AmendmentAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5629908830264263961L;
	
	private FileMgrManager fileMgrManager;
	
	protected PaginateListFactory paginateListFactory;
	
	private ExtendedPaginatedList rejectedFileList;
	
	private Long[] ids;
	
	@Autowired
	public void setFileMgrManager(FileMgrManager fileMgrManager) {
		this.fileMgrManager = fileMgrManager;
	}
	
	@Autowired
    public void setPaginateListFactory(PaginateListFactory paginateListFactory) {
        this.paginateListFactory = paginateListFactory;
    }
	

	public Long[] getIds() {
		return ids;
	}

	public void setIds(Long[] ids) {
		this.ids = ids;
	}

	public String view() {
//		User currentUser = (User)ActionContext.getContext().getSession().get(WebConstants.USER_INFO);
//		ExtendedPaginatedList paginatedList = paginateListFactory.getPaginatedListFromRequest(ServletActionContext.getRequest());
//		rejectedFileList = this.rejectedFileManager.getListByReceiver(currentUser.getId(), paginatedList);
		return SUCCESS;
	}
	
	public String remove() {
		
		//Update TBL_FILE_MANAGEMENT
		fileMgrManager.removeAmendment(ids);
		
		ActionContext.getContext().getSession().put("message", getText("amendmentFile.save.successfully"));
		
		return SUCCESS;
	}

	public void setRejectedFileList(ExtendedPaginatedList rejectedFileList) {
		this.rejectedFileList = rejectedFileList;
	}

	public ExtendedPaginatedList getRejectedFileList() {
		User currentUser = (User)ActionContext.getContext().getSession().get(WebConstants.USER_INFO);
		ExtendedPaginatedList paginatedList = paginateListFactory.getPaginatedListFromRequest(ServletActionContext.getRequest());
		
		rejectedFileList = this.fileMgrManager.getAmendmentFile(currentUser.getId(), paginatedList);
		return rejectedFileList;
	}
}
